package com.situ.service.impl;

import com.situ.bean.Order;
import com.situ.bean.OrderResponse;
import com.situ.bean.Orderinfo;
import com.situ.dao.OrderDao;
import com.situ.dao.OrderMapper;
import com.situ.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class OrderService implements IOrderService {
    @Autowired
    private OrderDao orderDao;

    @Override
    public void addorderinfo(Orderinfo orderinfo) {
        orderDao.addorderinfo(orderinfo);
    }

    @Override
    public boolean addorder(Order order) {
        if (orderDao.addorder(order)) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public Order getorder(Order order) {
        return orderDao.getorder(order);
    }

    @Override
    public boolean updateorder(Order order) {
        return orderDao.updateorder(order);

    }

    @Override
    public int paymentsuccess(Order order) {
       return orderDao.paymentsuccess(order);
    }

    @Override
    public Order getpayorder(Order order) {
        return orderDao.getpayorder(order);
    }

    @Override
    public List<Order> getUnpaidOrders() {
        return orderDao.getUnpaidOrders();
    }




    @Autowired
    private OrderMapper orderMapper;
    public OrderResponse getOrdersWithDetailsByUserId(int userid) {
        OrderResponse response = new OrderResponse();
        response.setOrders(orderMapper.getOrdersByUserId(userid));
        response.setOrderDetails(orderMapper.getOrderDetailsByUserId(userid));
        return response;
    }






//admin
    // 获取所有订单
    public List<Order> getAllOrders() {
        return orderMapper.selectAllOrders();
    }

    // 根据ID获取订单
    public Order getOrderById(int id) {
        return orderMapper.selectOrderById(id);
    }

    // 更新订单

    @Override
    public boolean updateOrders(Order order) {
       return orderDao.updateOrders(order);
    }

    // 删除订单
    public void deleteOrder(int id) {
        orderMapper.deleteOrder(id);
    }










}